import React ,{useState}from 'react'
import './Login.css';
import { Form, Input, Button, Checkbox } from 'antd';
import { UserOutlined, LockOutlined } from '@ant-design/icons';
import { useHistory } from 'react-router-dom';
import Password from 'antd/lib/input/Password';
import http from '../../utils/http'

export default function Login() {
    const onFinish=(e)=>{
        console.log(e.username,e.password)
        http({
            url:'/huangying/login',
            method:"get",
            data:{
                user_name:e.username,
                password:e.password
            }
            
        }).then((res)=>{
            console.log(res);
            if(res.message=='登录成功'){
                his.push('/admin/Home');
            }
            
        })

    }

    //点击跳转到首页
    const his = useHistory();
    const toHome=(i)=>{
        
        
    }

    return (
        <div className="box">
        <Form
            name="normal_login"
            className="login-form"
            initialValues={{ remember: true }}
            onFinish={onFinish}
        >
            <Form.Item
                name="username"
                rules={[{ required: true, message: '请输入账号！' }]}
            >
                <Input 
                prefix={<UserOutlined className="site-form-item-icon" />} 
                placeholder="Username" />
            </Form.Item>
            <Form.Item
                name="password"
                rules={[{ required: true, message: '请输入密码！' }]}
            >
                <Input
                    prefix={<LockOutlined className="site-form-item-icon" />}
                    type="password"
                    placeholder="Password"
                />
            </Form.Item>
            <Form.Item>
                <Form.Item name="remember" valuePropName="checked" noStyle>
                    <Checkbox>Remember me</Checkbox>
                </Form.Item>


            </Form.Item>

            <Form.Item>
                <Button onClick={toHome} type="primary" htmlType="submit" className="login-form-button">
                    登录
                </Button>

            </Form.Item>
        </Form>
    </div>
    )
}
